<template>
    <div class="page">
        <AdminTabsP :list="tabList" v-model:active="tabActive" />

        <AdminSearchInputP @search="onSearch" placeholder="搜索模板名称" />

        <div
            class="buy-list"
            v-loading="isLoading"
            v-if="filterList.length || isLoading"
        >
            <template v-for="item in renderList" :key="item.id">
                <div class="buy-item">
                    <div class="buy-item__image">
                        <img
                            :src="
                                item.info
                                    ? item.info.file +
                                      '?x-oss-process=image/watermark,image_' +
                                      toBase64(
                                          'water/logo_white.png?x-oss-process=image/resize,P_30'
                                      ) +
                                      ',g_center,t_60'
                                    : ''
                            "
                        />
                    </div>
                    <div class="buy-item__main">
                        <div class="main-top">
                            {{ item.info ? item.info.name : "-" }}
                        </div>

                        <div class="main-cell">
                            <div class="main-cell__item">
                                模版ID：{{ item.info ? item.info.id : "-" }}
                            </div>
                            <div class="main-cell__item">
                                创建时间：{{
                                    item.info ? item.info.createtime : "-"
                                }}
                            </div>
                            <div class="main-cell__item" v-if="tabActive == 1">
                                过期时间：{{ item.validityendtime }}
                            </div>
                        </div>
                    </div>
                    <div class="buy-item__right">
                        <div class="btn" @click="onEdit(item)">
                            {{
                                {
                                    1: "编辑",
                                    2: "开始学习",
                                }[tabActive]
                            }}
                        </div>
                    </div>
                </div>
            </template>
        </div>

        <div class="pagination-box" v-if="filterList.length">
            <el-pagination
                small
                background
                v-model:current-page="pagination.page"
                v-model:page-size="pagination.size"
                layout="total, prev, pager, next, jumper"
                :total="filterList.length"
            />
        </div>

        <el-empty :image-size="150" v-if="!filterList.length && !isLoading" />
    </div>
</template>
<script setup>
import { useContent } from ".";

const {
    tabActive,
    tabList,
    filterList,
    pagination,
    renderList,
    isLoading,
    GetList,
    onSearch,
    onEdit,
} = useContent();

await GetList();
</script>
<style lang="scss" scoped>
.page {
    width: 100%;
    padding: 0 16px;
}

.buy-list {
    overflow: auto;
    background-color: #fff;
    border-radius: 6px;
    height: calc(100% - 185px);

    .buy-item {
        display: flex;
        padding: 12px;
        border-bottom: 1px solid #ddd;

        &__image {
            width: 100px;
            height: 90px;

            img {
                width: 100%;
                height: 100%;
                border-radius: 6px;
                object-fit: cover;
            }
        }

        &__main {
            padding-left: 18px;
            padding-top: 8px;
            padding-bottom: 5px;
            display: flex;
            flex-direction: column;

            .main-cell {
                margin-top: auto;
                display: flex;
                color: #666;

                &__item {
                    margin-right: 30px;
                }
            }
        }

        &__right {
            margin-left: auto;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding-top: 8px;

            .price {
                color: #5185fb;
                font-size: 20px;
                font-weight: 500;
            }

            .btn {
                margin-top: auto;
                display: inline-flex;
                align-items: center;
                justify-content: center;
                height: 30px;
                background-color: #5185fb;
                border-radius: 4px;
                color: #fff;
                font-size: 16px;
                cursor: pointer;
                user-select: none;
                padding: 0 10px;
            }
        }
    }
}

.pagination-box {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}
</style>
